package com.ruoyi.web.controller.spoken;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.ISpokenOrderService;
import com.ruoyi.system.service.ISpokenTeacherService;
import com.ruoyi.system.service.ISpokenUserCourseTimeService;
import com.ruoyi.system.service.ISpokenUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(description = "统计模块")
@RequestMapping("/spoken/statistics")
@RestController
public class StatisticsController extends BaseController {

    @Autowired
    ISpokenUserService userService;

    @Autowired
    ISpokenTeacherService teacherService;

    @Autowired
    ISpokenOrderService orderService;

    @Autowired
    ISpokenUserCourseTimeService userCourseTimeService;


    @ApiOperation("查询用户数量")
    @PostMapping("/queryUser")
    public AjaxResult queryUser(@RequestBody Map param){
        List<String> date = (List)param.get("date");
        String startDate = "";
        String endDate = "";
        if(date.size() > 0){
            startDate = date.get(0);
            endDate = date.get(1);
        }
        return success(userService.selectUserCount(startDate, endDate));
    }

    @ApiOperation("查询教师数量")
    @PostMapping("/queryTeacher")
    public AjaxResult queryTeacher(@RequestBody Map param){
        List<String> date = (List)param.get("date");
        String startDate = "";
        String endDate = "";
        if(date.size() > 0){
            startDate = date.get(0);
            endDate = date.get(1);
        }
        return success(teacherService.selectTeacherCount(startDate, endDate));
    }

    @ApiOperation("查询订单数量")
    @PostMapping("/queryOrder")
    public AjaxResult queryOrder(@RequestBody Map param){
        String status = (String)param.get("status");
        Integer statusInt = null;
        if(!status.equals("")){
            statusInt = Integer.valueOf(status);
        }
        List<String> date = (List)param.get("date");
        String startDate = "";
        String endDate = "";
        if(date.size() > 0){
            startDate = date.get(0);
            endDate = date.get(1);
        }
        return success(orderService.selectOrderCount(statusInt, startDate, endDate));
    }

    @ApiOperation("查询消课数量")
    @PostMapping("/queryCancelLesson")
    public AjaxResult queryCancelLesson(@RequestBody Map param){
        Integer teacherIdInt = (Integer)param.get("teacherId");
        Long teacherId = null;
        if(teacherIdInt != null){
            teacherId = Long.valueOf(teacherIdInt);
        }
        List<String> date = (List)param.get("date");
        String startDate = "";
        String endDate = "";
        if(date.size() > 0){
            startDate = date.get(0);
            endDate = date.get(1);
        }
        return success(userCourseTimeService.selectTeacherCancelLessonCount(teacherId, startDate, endDate));
    }
}
